(function (vc, vm) {

    vc.extends({
        data: {
            editIntegralShopRuleInfo: {
                ruleId: '',
                ruleName: '',
                money: '',
                amount: '',
            }
        },
        _initMethod: function () {

        },
        _initEvent: function () {
            vc.on('editIntegralShopRule', 'openEditIntegralShopRuleModal', function (_params) {
                $that.refreshEditIntegralShopRuleInfo();
                $('#editIntegralShopRuleModel').modal('show');
                vc.copyObject(_params, $that.editIntegralShopRuleInfo);
                $that.editIntegralShopRuleInfo.shopId = vc.getCurrentCommunity().shopId;
            });
        },
        methods: {
            editIntegralShopRuleValidate: function () {
                return vc.validate.validate({
                    editIntegralShopRuleInfo: $that.editIntegralShopRuleInfo
                }, {
                    'editIntegralShopRuleInfo.ruleName': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "规则名称不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "128",
                            errInfo: "规则名称不能超过128"
                        },
                    ],
                    'editIntegralShopRuleInfo.money': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "金额不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "30",
                            errInfo: "金额不能超过30"
                        },
                    ],
                    'editIntegralShopRuleInfo.amount': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "积分数不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "30",
                            errInfo: "积分数不能超过30"
                        },
                    ],
                    'editIntegralShopRuleInfo.ruleId': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "编号不能为空"
                        }]

                });
            },
            editIntegralShopRule: function () {
                if (!$that.editIntegralShopRuleValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }

                vc.http.apiPost(
                    '/integralShopRule.updateIntegralShopRule',
                    JSON.stringify($that.editIntegralShopRuleInfo),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            $('#editIntegralShopRuleModel').modal('hide');
                            vc.emit('integralShopRule', 'listIntegralShopRule', {});
                            return;
                        }
                        vc.toast(_json.msg);
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');

                        vc.toast(errInfo);
                    });
            },
            refreshEditIntegralShopRuleInfo: function () {
                $that.editIntegralShopRuleInfo = {
                    ruleId: '',
                    ruleName: '',
                    money: '',
                    amount: '',

                }
            }
        }
    });

})(window.vc, window.$that);
